﻿Imports System.Data
Imports System.Data.SqlClient
Partial Class nGiaFr
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then
            BindGrid()
        End If
    End Sub


    Private Sub BindGrid()
        Dim idsanpham As Int16 = -1
        If IsNumeric(Request.QueryString("id")) Then
            idsanpham = Request.QueryString("id")
        End If

        Dim myConn As New SqlConnection(ConfigurationManager.AppSettings("cons"))
        Dim strWhere As String = ""
        If TextBox1.Text <> "" Then
            strWhere += " and tenquicachV like N'%" & TextBox1.Text & "%'"
        End If
        Dim sSql As String = "select idquicach,  tenquicachV,tenquicachE,tenquicachF,tenquicachG,tenquicachC,tenquicachS,giaV,giaE,giaF,giaC,chuan,nhom  from quicach where idsanpham=" & idsanpham & strWhere & " order by nhom, giaV"
        myConn.Open()
        Dim myAdapter As New SqlDataAdapter(sSql, myConn)
        Dim myDataSet As New DataSet
        myAdapter.Fill(myDataSet, sSql)
        DataGrid1.DataSource = myDataSet
        DataGrid1.DataBind()
        myConn.Close()
    End Sub




    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim sSql As String
        Dim intuser%
        Dim myConn As New SqlConnection(ConfigurationManager.AppSettings("cons"))
        Dim MyCommand As SqlCommand = Nothing
        Dim iLev As Integer = 1
        intuser = 1
        myConn.Open()

        Dim I As Integer
        For I = 0 To DataGrid1.Items.Count - 1
            Dim txtbox As TextBox = CType(DataGrid1.Items(I).FindControl("txtTD"), TextBox)
            sSql = " update quicach set giaf=@giaf where idquicach=@idquicach"
            MyCommand = New SqlCommand(sSql, myConn)
            MyCommand.Parameters.Add(New SqlParameter("@giaf", IIf(txtbox.Text = "", 0, CDbl(txtbox.Text))))
            MyCommand.Parameters.Add(New SqlParameter("@idquicach", DataGrid1.DataKeys(I)))
            MyCommand.ExecuteNonQuery()
            MyCommand.Dispose()
        Next
        MyCommand.Dispose()
        '-----------
        myConn.Close()
        BindGrid()
    End Sub

    Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        BindGrid()
    End Sub
End Class
